<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>个位数字为 K 的整数之和</title>
</head>
<body>
  <script>
    function fn(num, k) {
      const target = num % 10;
      if (num === 0) {
        return 0;
      }
      for (let i = 1; i <= 10; i++) {
        if ((k * i) % 10 === target) {
          if (num >= k * i) { // 数字够大
            return i;
          }
        }
      }
      return -1;
    }
    console.log(fn(58, 9))
  </script>
</body>
</html>